package com.apanal.qlife.sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.apanal.qlife.common.page.Page;
import com.apanal.qlife.common.page.PageReturn;
import com.apanal.qlife.sys.model.Area;
import com.apanal.qlife.sys.service.AreaService;

/**
 * @author Admin
 * 
 */
@Controller
@RequestMapping("area")
public class AreaController {

	@Autowired
	private AreaService areaService;

	@ResponseBody
	@RequestMapping("areaList")
	public List<Area> findAreaList(Area area) {
		return areaService.findAreaList(area);
	}

	/**
	 * 分页查询,json返回
	 * 
	 * @param Area
	 * @param page
	 * @param model
	 * @return
	 */
	// @RequiresPermissions("user:view")
	@ResponseBody
	@RequestMapping(value = "listJson", method = RequestMethod.GET)
	public PageReturn<Area> listJson(Area area, Page page, Model model) {
		if (area.getAreType() == 22) { // 平台
			area.setAreType(1);
		}
		if (area.getAreType() == 23) { // 渠道
			area.setAreType(2);
		}
		if (area.getAreType() == 24) { // 物业
			area.setAreType(3);
		}
		return areaService.selectRelationForPage(area, page);
	}

	/**
	 * 根据id字符串查询
	 * 
	 * @param ids
	 *            逗号分隔
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/{ids}/selectByIds", method = RequestMethod.GET)
	public List<Area> selectByIds(@PathVariable("ids") String ids) {
		return areaService.selectByIds(ids);
	}
}
